#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int numberOfAlternatingGroups(vector<int>& colors) {
        int n = colors.size();
        int res = 0;
        for (int i = 0; i < n; i++)
        {
            int left = (i - 1 + n) % n;
            int right = (i + 1) % n;
            if (colors[right] == colors[left] && colors[left] != colors[i]) ++res;
        }
        return res;
    }
};